package com.liugui.basicsgrammar2;

/**
 * @ClassName: MaxAndMin
 * @Author: liugui
 * @Date: 2020-10-24 09:23
 **/
public class MaxAndMin {
    /**
     * 现给出一串数据（313, 89, 123, 323, 313, 15, 90, 56, 39）求出最大值和最小值并输出。
     */

    public static void main(String[] args) {

        int[] num = {313, 89, 123, 323, 313, 15, 90, 56, 39};
        int max = num[0],min = num[0];
        for (int i = 0; i < num.length - 1; i++) {
            if (num[i] > max) {
                max = num[i];
            }
            if (num[i] < min) {
                min = num[i];
            }
        }
        //方法二
        //Arrays.sort(data);
        //System.out.println(data[0]);
        //System.out.println(data[data.length - 1]);
        //方法三
        //System.out.println(Arrays.stream(data).min().getAsInt());
        //System.out.println(Arrays.stream(data).max().getAsInt());
        System.out.println("最大值:" + max);
        System.out.println("最小值:" + min);

    }
}
